﻿using ERPSystem.Common.Domains.Delivergoods;
using ERPSystem.Common.DTO;
using ERPSystem.Common.DTO.ShippingnoteDTO;
using ERPSystem.Enum.CommonErrorCodes;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.StaticFiles;
using NPOI.SS.UserModel;
using NPOI.XSSF.UserModel;
using SalesManagementCommon.API.SalesManagementCommons.Orderdetails;
using SalesManagementCommon.API.SalesManagementCommons.Shippingnotess;

namespace SalesManagementCommon.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ShippingController : ControllerBase
    {
        private readonly IMediator _mediator;

        public ShippingController(IMediator mediator)
        {
            _mediator = mediator;
        }
        /// <summary>
        /// 发货通知单显示
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ResultPage<ShippingnoteShowDTO>> ShippingnoteShowHandle([FromQuery] ShippingnoteQueryCommand request, CancellationToken cancellationToken)
        {
            return await _mediator.Send(request, cancellationToken);
        }
        /// <summary>
        /// 发货通知单导出
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<IActionResult> ShoppingExcelHandle([FromQuery] ShoppingExcelCommand request)
        {
            var result = await _mediator.Send(request);
            return File(result.FileBytes, result.MimeType, result.FileName);

        }
        /// <summary>
        /// 发货通知单反填
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Result<ShippintprintDTO>> ShippingnoteEditorHandle([FromQuery]ShippingnoteEditorCommand request, CancellationToken cancellationToken)
        {
            return await _mediator.Send(request, cancellationToken);
        }

        /// <summary>
        /// 销售订单明细
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Result<List<OrderdetailsDTO>>> OrderdetailsHandle([FromQuery] OrderdetailsCommand request, CancellationToken cancellationToken)
        {
            var result = await _mediator.Send(request, cancellationToken);
            return result;
        }

        /// <summary>
        /// 7天交货明细表
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<Result<List<DeliverydetailsDTO>>> DeliverydetailsHandle([FromQuery] DeliverydetailsCommand request, CancellationToken cancellationToken)
        {
            return await _mediator.Send(request, cancellationToken);
        }



    }
}
